feat: Add Ollama and local model support#26
feat: Add Ollama and local model support#26FrenzyVJN wants to merge 1 commit intohuggingface:mainfrom
Conversation
…luation
This commit adds comprehensive support for using Ollama and other local LLM providers (like LM Studio) with upskill's generate and eval commands.
## Changes
### Core Features
- Add --base-url and --provider flags to both generate and eval commands
- Monkey patch FastAgent's ModelFactory to handle unknown model names when GENERIC_BASE_URL is set
- Auto-detect 'generic' provider when --base-url is provided
- Set dummy API keys to bypass authentication checks when using local models
### Generation Improvements
- Update prompt to be more explicit for smaller models
- Add code fence stripping for models that wrap output in markdown blocks
- Pass model parameter through RequestParams to all FastAgent calls
- Support model override for all generation functions (generate_skill, generate_tests, improve_skill, refine_skill)
### Evaluation Improvements
- Add environment variable configuration for eval command
- Format model strings correctly for generic provider
- Support loading skills from ./skills/ directory
### Bug Fixes
- Fix classmethod monkey patch to properly access __func__
- Fix model formatting logic for eval_model parameter
- Add {{agentSkills}} placeholder to skill_gen agent card to enable skill loading
## Usage Examples
Generate skill with Ollama:
upskill generate "parse YAML" --model llama3.2:latest \
--base-url http://localhost:11434/v1 --no-eval
Evaluate skill with local model:
upskill eval ./skills/my-skill --model qwen2.5-coder:7b \
--base-url http://localhost:11434/v1 --tests tests.json
## Technical Details
The implementation uses FastAgent's generic provider support with environment variables:
- GENERIC_BASE_URL: Points to local API endpoint (e.g., http://localhost:11434/v1)
- GENERIC_API_KEY: Set to "local" (required but unused by Ollama)
- ANTHROPIC_API_KEY: Set to "dummy" to bypass startup checks
The monkey patch catches ModelConfigError for unknown models and falls back to generic provider when GENERIC_BASE_URL is configured.
## Limitations
Test case generation with --eval-model in generate command may not work due to FastAgent's structured() method not properly respecting model overrides. Workaround: use --no-eval and provide test cases manually with --tests flag.
|
Thanks for the patch -- for these models |
|
Good question — I tested this flow to confirm the behavior. Currently, There is also a secondary issue: when using the generic provider, the full model string ( The
That said, we could improve this further by stripping the Happy to implement that if you think it's the right direction — otherwise I'm comfortable keeping the current explicit configuration to avoid hidden magic. |
Add Ollama and Local Model Support
Summary
This PR adds comprehensive support for using Ollama and other local LLM providers (like LM Studio) with upskill's
generateandevalcommands. Users can now run skill generation and evaluation entirely locally without requiring API keys from cloud providers.Motivation
Currently, upskill requires API keys for cloud providers (Anthropic, OpenAI, etc.) to function. This PR enables:
Changes
New Command-Line Flags
Both
generateandevalcommands now support:--base-url <url>: Custom API endpoint for local models (e.g.,http://localhost:11434/v1)--provider <name>: API provider (optional, auto-detected asgenericwhen--base-urlis provided)Implementation Details
Model Factory Monkey Patch
ModelFactory.parse_model_string()to handle unknown model namesGENERIC_BASE_URLenvironment variable is setModelConfigErrorand returnsModelConfig(provider=Provider.GENERIC, model_name=model_string)Environment Variable Configuration
GENERIC_BASE_URLto point to local API endpointGENERIC_API_KEYto "local" (required but unused by Ollama)ANTHROPIC_API_KEYto "dummy" to bypass startup checksModel String Formatting
anthropic.claude-3-5-sonnet)llama3.2:latest)Small Model Improvements
Skills Directory Support
./skills/directory if it exists{{agentSkills}}placeholder to skill_gen agent cardUsage Examples
Generate Skill with Ollama
Evaluate Skill with Local Model
Testing
Tested with:
./skills/directory--no-eval--tests)Example Test Results
Hello World Skill with qwen2.5-coder:7b:
Known Limitations
Test Case Generation: The
--eval-modelflag with automatic test generation may not work due to FastAgent'sstructured()method not properly respecting model overrides.Workaround: Use
--no-evalflag during generation, then create test cases manually and run eval separately:Small Model Quality: Models like llama3.2 (3B parameters) may produce lower quality skills compared to larger cloud models. Recommended to use 7B+ models like qwen2.5-coder:7b for better results.
Backwards Compatibility
All changes are fully backwards compatible:
Files Changed
src/upskill/cli.py(+148 lines): Added Ollama support, new flags, environment setupsrc/upskill/generate.py(+36 lines): Code fence stripping, improved prompts, RequestParams supportsrc/upskill/agent_cards/skill_gen.md(+2 lines): Added{{agentSkills}}placeholderFuture Improvements
Potential follow-ups (not in this PR):
Checklist